package com.mc.array;

public class SumArray {
	public static int maxSum(int[] a){
		if(a==null)
			return Integer.MIN_VALUE;
		int currSum = 0;
		int totalSum = 0;
		
		for(int i=0;i<a.length;i++){
			if(currSum<=0)
				currSum = a[i];
			else
				currSum+=a[i];
			if(currSum>totalSum)
				totalSum = currSum;
		}
		return totalSum;
	}
	
	public static void main(String[] args) {
		int res = SumArray.maxSum(new int[]{1,-2,3,10,-4,7,2,-5});
		System.out.println(res);
	}
}	
